package com.ruoyi.project.applet.controller;

import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.framework.aspectj.lang.annotation.Log;
import com.ruoyi.framework.aspectj.lang.enums.BusinessType;
import com.ruoyi.framework.web.controller.BaseController;
import com.ruoyi.framework.web.domain.AjaxResult;
import com.ruoyi.framework.web.page.TableDataInfo;
import com.ruoyi.project.applet.domain.Wallet;
import com.ruoyi.project.applet.service.IWalletService;
import com.ruoyi.project.system.domain.SysUserWx;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 钱包Controller
 * 
 * @author ruoyi
 * @date 2023-06-16
 */
@RestController
@RequestMapping("/wx/wallet")
@Api("钱包管理")
public class WalletController extends BaseController
{
    @Autowired
    private IWalletService walletService;

    /**
     * 查询钱包列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Wallet wallet)
    {
        startPage();
        List<Wallet> list = walletService.selectWalletList(wallet);
        return getDataTable(list);
    }

    /**
     * 导出钱包列表
     */
    @Log(title = "钱包", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Wallet wallet)
    {
        List<Wallet> list = walletService.selectWalletList(wallet);
        ExcelUtil<Wallet> util = new ExcelUtil<Wallet>(Wallet.class);
        return util.exportExcel(list, "wallet");
    }

    /**
     * 获取钱包详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(walletService.selectWalletById(id));
    }

    /**
     * 获取钱包详细信息
     */
    @ApiOperation(value = "账户余额")
    @GetMapping("/token")
    public AjaxResult getByToken()
    {
        final SysUserWx userWx = getLoginUser().getUserWx();

        return AjaxResult.success(walletService.getWalletMoney(userWx.getOpenId()));
    }


}
